<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<html>
<head> 
<style>
	.TDL{
		text-align:right;
		width:12%;		
		nowrap:nowrap;
	}
	.TDC{
		text-align:left;
		width:10%;
		nowrap:nowrap;
	}
</style>
</head>
<title>存储数据源配置</title>  
<jsp:include page="/include.jsp"/>
<script type="text/javascript">
   //新增存储数据源配置信息窗口
   function doAddNoSql(){
	  	window.top.$('<div id="saveDiv"/>').dialog({
		href:'${pageContext.request.contextPath}/basemgr/noSqlConfigAction!forwardAdd.action',
		top:($(window.top).height()-400)*0.5,
	    left:($(window.top).width()-400)*0.5,
	    width:400,
		modal:true,
		title:'新增存储数据源',
		buttons:[{
			id:'btnCheck',
			text:'存储数据源验证',
			iconCls:''		
			},
			{
			id:'btnSave',
			text:'保 存',
			iconCls:''
		}],
		onClose:function(){
			window.top.$(this).dialog('destroy');
			$('#nosql_table_datagrid').datagrid('reload');
		}
	});
   }
   //修改存储数据源配置信息窗口
   function doEditNoSql(id){
		window.top.$('<div id="updateDiv"/>').dialog({
			href:'${pageContext.request.contextPath}/basemgr/noSqlConfigAction!forwarEdit.action?id='+id,
			top:($(window.top).height()-400)*0.5,
		    left:($(window.top).width()-400)*0.5,
			width:400,
			modal:true,
			title:'修改存储数据源配置信息',
			buttons:[{
				id:'btnCheck',
				text:'存储数据源验证',
				iconCls:''			
			},{
				id:'btnSave',
				text:'保 存',
				iconCls:''
			}],
			onClose:function(){
				window.top.$(this).dialog('destroy');
				$('#nosql_table_datagrid').datagrid('reload');
			}
		});
   }
   //删除
   function doDeleteNoSql(id){
	   $.ajax({
		   url:'${pageContext.request.contextPath}/basemgr/noSqlConfigAction!deleteBeforeCheck.action',
		   dataType:'json',
		   data:{databaseId:id},
		   success:function(result){
			   if (result)
			   {
				   $.messager.show({title:'提示',msg:"此目标存储数据源已被使用,无法删除"});
			   }
			   else
			   {
				   window.top.$.messager.confirm('提示','是否确定删除该条记录？',function(b){
						  if(b){
							  $.ajax({
								  url:'${pageContext.request.contextPath}/basemgr/noSqlConfigAction!deleteNoSqlById.action',
								   dataType:'json',
								   data:{databaseId:id},
								   success:function(data){
									   var msg = "";
									   if (data!=null)
									   {
										   if (data.returnMsg == '1')
										   {
											   msg = "删除目标存储数据源成功";
										   }
										   else if (data.returnMsg == '-1')
										   {
											   msg = "参数为空";
										   }
										   else
										   {
											   msg = "删除目标存储数据源失败";
										   }
									   }
									   else
									   {
										   msg = "删除目标存储数据源失败";
									   }
									   $.messager.show({title:'提示',msg:msg});
									   //刷新主列表
									   $('#nosql_table_datagrid').datagrid('reload');	
								   }
							   });	  
							  
						  }
					  });
			   }
		   }
	   });
   } 
   
//执行查询
function doQuery(){	
	if ($("#nosql_query_form").form("validate"))
	{
		$("#nosql_table_datagrid").datagrid('options').queryParams=serializeObject($('#nosql_query_form')); //把查询条件赋值给datagrid内部变量
		$("#nosql_table_datagrid").datagrid('load'); //重新加载
	}
}
//重置查询条件
function doReset(){
	$('#nosql_query_form').form('reset');
}
   //页面加载完后响应 onReady
$(function(){
	//查询按纽绑定事件
	$('#btnQuery').bind('click',doQuery);
	//重置按纽绑定事件
	$('#btnReset').bind('click',doReset);
	$('#nosql_query_domain').combobox({
		url:'${pageContext.request.contextPath}/basemgr/kqiManagerAction!getDic.action?dictType=DOMAIN&list=list',  
		valueField:'codeValue',
		textField:'codeName',
 	 	editable:false,
 		onLoadSuccess:function(){
			$(this).combobox('select',null);
		}
	 	
	});	
	//初始化主列表
	$('#nosql_table_datagrid').datagrid({
		url:'${pageContext.request.contextPath}/basemgr/noSqlConfigAction!getAllNosqlConigList.action',
		fit:true,
		border:false,
		fitColumns:true,
		pagination:true,
		pageList:[10,20,30],
		rownumbers:false,
		sortName:'databaseId',
		sortOrder:'desc',		
		singleSelect:true,
		striped:true,
		columns:[[
		          {field:'hostName',title:'主机地址',width:150,align:'center',sortable:true},
		          {field:'port',title:'端口号',width:200,align:'center',sortable:true},
		          {field:'keySpace',title:'模式名',width:250,align:'center',sortable:true},
		          {field:'domainName',title:'域 名',width:150,align:'center'},
		          {field:'action',title:'操 作',width:150,align:'left',
		        	  formatter:function (value,row,index){
						var str='<span  style="cursor:pointer" onclick="doEditNoSql(\''+row.databaseId+'\')"><img  src="${pageContext.request.contextPath}/images/icons/modify_or_edit.png" title="修改" alt="修改"/>修改&nbsp;&nbsp;</span>'
								+ '<span style="cursor:pointer" onclick="doDeleteNoSql(\''+row.databaseId+'\')"><img src="${pageContext.request.contextPath}/images/icons/delete.png" title="删除" alt="删除" style="margin-top:2px;">删除&nbsp;&nbsp;</span>';	
		        	  	return str;
		        	  }
				  }
		        ]],
		toolbar:'#nosql_table_datagrid_toobar'
	});
});
</script>
<body class="easyui-layout">  
	<form id="nosql_query_form" method="post">
	    <div data-options="region:'north'" style="height:80px;border-bottom:none;border-top:none;">
	    	<table border="0" cellpadding="0" cellspacing="0" height="100%"  width="100%" >
	    		<tr>
	    		    <td style="width:10%;text-align:right;" nowrap="nowrap">
						<label for="nosql_query_hostName">主机地址：</label>
					</td>
					<td style="width:15%;text-align:left;" nowrap="nowrap">
						<input type="text" id="nosql_query_hostName" name="hostName" class="easyui-validatebox" data-options="validType:'ipValidate'"/>
					</td>
					<td style="width:10%;text-align:right;" nowrap="nowrap">
						<label for="nosql_query_port">端口号：</label>
					</td>
					<td style="width:15%;text-align:left;" nowrap="nowrap">
						<input type="text" id="nosql_query_port" name="port" class="easyui-numberbox"/>
					</td>
					<td style="width:10%;text-align:right;" nowrap="nowrap">
						<label for="nosql_query_keySpace">模式名：</label>
					</td>
					<td style="width:15%;text-align:left;" nowrap="nowrap">
						<input type="text" id="nosql_query_keySpace" name="keySpace" class="easyui-validatebox" data-options="validType:'specialCharFilter'"/>
					</td>
					<td style="width:10%;text-align:right;" nowrap="nowrap">
						<label for="nosql_query_keySpace">域 名：</label>
					</td>
					<td style="width:15%;text-align:left; padding-right:55px" nowrap="nowrap">
						<input type="text" id="nosql_query_domain" class="easyui-combobox" name="domain" panelHeight="auto"/>			
					</td>	    		    
	    		</tr> 
	    		<tr>
	    			<td style="text-align:right;width:10%;" nowrap="nowrap">
	    			</td>
	    			<td style="text-align:left;width:15%;" nowrap="nowrap">
	    			</td>
	    			<td style="text-align:right;width:10%;" nowrap="nowrap">
	    			</td>
	    			<td style="text-align:left;width:15%;" nowrap="nowrap">
	    			</td>
	    			<td style="text-align:right;width:10%;" nowrap="nowrap">
	    			</td>
	    			<td style="text-align:left;width:15%;" nowrap="nowrap">
	    			</td>    		
	    			<td colspan="2" style="width:25%;text-align:right;" nowrap="nowrap">	   
						<input type="button" id="btnQuery" value="查 询" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/search.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;"/>	
			    		<input type="button" id="btnReset" value="重 置" style="cursor:pointer;background-image: url('${pageContext.request.contextPath}/images/login/reset.png');background-repeat: no-repeat;width:67px;height:23px;padding-left:12px;border:none;color:white;font-family:微软雅黑;margin-right:55px"/>		
	    			</td>
	    		</tr>			    						    	    		
	    	</table>	    	
	    </div>  
	    <div data-options="region:'center'" style="border-top:none">
			<table id="nosql_table_datagrid"></table>
			<div id="nosql_table_datagrid_toobar" class="etl_panel_title" >
				<a href="javascript:void(0);" onclick="doAddNoSql()" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" style="float:left;">新增</a>
			</div>
		</div> 
    </form>
</body>  
</html>

